/*************************************************************************
    > File Name    : test.c
    > Author       : fengchaopeng
    > Mail         : bingyaxuan@126.com 
    > Created Time : 2021-02-25 16:16:11 星期四 HKT
 ************************************************************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "cJsonFile.h"

#define MAX_SIZE  10240

int main(int argc, char const* argv[])
{
	if(argc != 2)
	{
		return -1;
	}
	char filename[30] = {0};
	strcpy(filename, argv[1]);
	unsigned char jsonBuf[MAX_SIZE] = {0};
	int ret = readFileContents(filename, jsonBuf, MAX_SIZE);
	//printf("result[%d]:\n%s\n", ret, jsonBuf);

	cJSON* root = NULL;
	root = cJSON_Parse(jsonBuf);
	if(!root)
	{
		printf("读取文件失败: %s\n", cJSON_GetErrorPtr());
		exit(0);
	}
	printf("%s\n", cJSON_Print(root));

	cJSON* zigbeeCOM = NULL;
	cJSON* voiceCOM = NULL;
	cJSON* inNet = NULL;
	cJSON* outNet1 = NULL;
	cJSON* outNet2 = NULL;
	zigbeeCOM = cJSON_GetObjectItem(root, "zigbeeCOM");
	voiceCOM = cJSON_GetObjectItem(root, "voiceCOM");
	inNet = cJSON_GetObjectItem(root, "inNet");
	outNet1 = cJSON_GetObjectItem(root, "outNet1");
	outNet2 = cJSON_GetObjectItem(root, "outNet2");
	changeIntValuesByKey(voiceCOM, "baudrate", 9600);
	printf("%s\n", cJSON_Print(root));
	return 0;

	char baudrate[2] = {0};
	strcpy(baudrate, cJSON_GetObjectItem(zigbeeCOM, "stopbits")->valuestring);
	printf("%d\n", cJSON_GetObjectItem(zigbeeCOM, "stopbits")->valuestring[0]);
	printf("%d\n", baudrate[0]);

	writeJson2File(root, filename);
	return 0;
    
    return 0;
}
